package com.hzdl.cinema.web.servlet;

import com.hzdl.cinema.Service.TicketService;
import com.hzdl.cinema.Service.impl.TicketServiceImpl;
import com.hzdl.cinema.domain.PageBean;
import com.hzdl.cinema.domain.Ticket;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;

@WebServlet("/ticket/*")
public class TicketServlet extends BaseServlet {

    TicketService ticketService = new TicketServiceImpl();

//    public void findTicketByUserId(HttpServletRequest request, HttpServletResponse response) throws IOException {
//        int userId = Integer.parseInt(request.getParameter("userId"));
//        PageBean<Ticket> pageBean=ticketService.findMyTicket(userId);
//        writeValue(response,pageBean);
//
//    }
    public void returnTicket(HttpServletRequest request, HttpServletResponse response) throws IOException {
        int ticketId = Integer.parseInt(request.getParameter("ticketId"));
        ticketService.returnTicket(ticketId);
        writeValue(response,"退票成功！");
    }

    public void findPage(HttpServletRequest request, HttpServletResponse response) throws IOException {
        int userId = Integer.parseInt(request.getParameter("userId"));
        int currentPage = Integer.parseInt(request.getParameter("currentPage"));
        int rows = Integer.parseInt(request.getParameter("rows"));
        PageBean<Ticket> ticketPage=ticketService.findPage(userId,currentPage,rows);
        writeValue(response,ticketPage);
    }
	 public void seeTicket(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String rows = request.getParameter("rows");

        String currentPage = request.getParameter("currentPage");

        PageBean<Ticket> pageBean= ticketService.seeTicke(Integer.valueOf(rows),Integer.valueOf(currentPage));
        writeValue(response,pageBean);

    }

    public void numTicket(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        BigDecimal bigDecimal=  ticketService.numTicket();
        writeValue(response,bigDecimal);
    }

    public void seeStudio(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        String studioId = request.getParameter("studioId");
//        Studio studio=scheduleService.seeStudio(studioId);
//        writeValue(response,studio);
    }
}
